package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class BatugailuKengailu extends Konbinazionalak {
	private Color kolorea;
	private Vector<Hanka> hankaBektorea=new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea=new Vector<Hanka>();
	private Hanka s1, s2,i3,i4, i1,i2,s3;
	public BatugailuKengailu(int x1, int y1, int hankaKop, int sarreraKopMax, String mota) {
		super(x1, y1, hankaKop, sarreraKopMax, mota);
		// TODO Auto-generated constructor stub
		s1 = new Hanka(x+20, y-20, "positiboa", "s", 0, this, "b","ez");
		s2 = new Hanka(x+40 , y-20, "positiboa", "s", 1, this, "b","ez");
		
		s3 = new Hanka(x-20 , y+20 , "positiboa", "s", 2, this, "h","ez");
		i1 = new Hanka(x+30 , y+60 , "positiboa", "i", 3, this, "b","ez");
		i2 = new Hanka(x+80 , y +20, "positiboa", "i", 4, this, "h","ez");
		lotList[0]=s1;
		lotList[1]=s2;
		lotList[3]=i1;
		lotList[4]=i2;
		
		lotList[2]=s3;
	}
	public void dibujate(Graphics g) {

		g.setColor(Color.black);
		//goikoa
		g.drawLine(x, y,x+60, y);
		//beikoa
		g.drawLine(x+60, y ,x+60, y + 40);
		//ezkerretakoa
		g.drawLine(x+60, y+40, x, y + 40);
		//eskubitakoa
		g.drawLine(x, y+40, x, y );
		if(this.mota=="bat"){
			g.drawString("Bat", x+20, y+23);
			g.drawString("Cin", x+1 , y+38);
			g.drawString("Cout", x+33 , y +38);
		}
		if(this.mota=="ken"){
			g.drawString("Ken", x+20, y+23);
			g.drawString("Cin", x+1 , y+38);
			g.drawString("Cout", x+33 , y +38);
		}
		if(this.mota=="batken"){
			g.drawString("Bat/Ken", x+10, y+23);
			g.drawString("Cin", x+1 , y+38);
			g.drawString("Cout", x+33 , y +38);
		}
			s1.dibujate(g);
			s2.dibujate(g);
			i1.dibujate(g);
			i2.dibujate(g);
			
			s3.dibujate(g);
		
	}
	public boolean estaDentro(int x, int y) {
		if ((x > this.x) && (x < (this.x + 60)) && (y > this.y)
				&& (y < (this.y + 40))) {
			return true;
		}
		return false;

	}
	public void setPosicion(int x1, int y1) {
		this.x = x1;
		this.y = y1;
	}

	public int getX() {
		return x;
	}
	public int getY() {
		return y;
	}
	@Override
	public void funtzioLogikoa(Integer... values) {
		
		// TODO Auto-generated method stub
		if(this.mota=="bat"){
		lotList[3].getIrteera().setBalioa(s1.getSarrera().getBalioa() ^ s2.getSarrera().getBalioa()^ s3.getSarrera().getBalioa());
		lotList[4].getIrteera().setBalioa((s1.getSarrera().getBalioa() & s2.getSarrera().getBalioa())|( s3.getSarrera().getBalioa()&(s1.getSarrera().getBalioa() ^ s2.getSarrera().getBalioa())));
		}
		if(this.mota=="ken"){
			lotList[3].getIrteera().setBalioa((not(s1.getSarrera().getBalioa()) & s2.getSarrera().getBalioa())|( s1.getSarrera().getBalioa()&not(s2.getSarrera().getBalioa())^1));
			//lotList[3].getIrteera().setBalioa((s1.getSarrera().getBalioa() & s2.getSarrera().getBalioa())|( s3.getSarrera().getBalioa()&(s1.getSarrera().getBalioa() ^ s2.getSarrera().getBalioa())));
			lotList[4].getIrteera().setBalioa(0);	
		}
		if(this.mota=="batken"){
			if(s3.getSarrera().getBalioa()==0)
			lotList[3].getIrteera().setBalioa(s1.getSarrera().getBalioa() |( s2.getSarrera().getBalioa()^0)|0);
			else if(s3.getSarrera().getBalioa()==1)
				lotList[3].getIrteera().setBalioa(s1.getSarrera().getBalioa() |( s2.getSarrera().getBalioa()^1)|1);
			}
		}
		
	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(s3);
		hankaBektorea.addElement(i1);
		hankaBektorea.addElement(i2);

		return hankaBektorea;
	}

	@Override
	public Hanka getIrteeraHanka() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea=new Vector<Hanka>();
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		sarreraBektorea.addElement(s3);
		return sarreraBektorea;
	}
public Integer not(Integer sar){
	if (sar==0)
		return 1;
	else return 0;
}


}
